package com.zmn.oms.common.enums;

import com.zmn.consts.DictModel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

/**
 * 类描述: 改派申请改派状态枚举类
 *
 * @author: HuangChao
 * @since: 2022/05/09 16:47
 */
@AllArgsConstructor
@Getter
public enum RedistributeStatusEnum {
    WAIT_REDISTRIBUTE(1, "待改派"),
    REDISTRIBUTE_FAIL(2, "改派失败"),
    REDISTRIBUTE_SUCCESS(3, "改派成功"),
    CANCEL_REDISTRIBUTE(4, "取消改派"),
    ;

    private Integer code;
    private String desc;


    /**
     * 改派状态列表
     *
     * @return
     */
    public static List<DictModel> getRedistributeStatusList() {
        List<DictModel> items = new ArrayList<>(4);
        items.add(new DictModel(1, "待改派"));
        items.add(new DictModel(2, "改派失败"));
        items.add(new DictModel(3, "改派成功"));
        items.add(new DictModel(4, "取消改派"));
        return items;
    }

    /**
     * 获取枚举
     *
     * @param code
     * @return
     */
    public static RedistributeStatusEnum getEnum(Integer code) {
        return Arrays.stream(RedistributeStatusEnum.values())
                .filter(e -> Objects.equals(code, e.getCode()))
                .findFirst()
                .orElseThrow(() ->new IllegalStateException(String.format("code:%s 获取不到枚举", code)));
    }

    /**
     * 获取枚举描述
     *
     * @param code
     * @return
     */
    public static String getEnumDesc(Integer code) {
        return getEnum(code).getDesc();
    }
}
